package cn.ustb.controller;

import cn.ustb.entity.StudentGrade;
import cn.ustb.service.StudentGradeService;
import cn.ustb.serviceImpl.StudentGradeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author yuyan
 */
@WebServlet("/getStudentGradeServlet")
public class getStudentGradeServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    StudentGradeService studentGradeService=new StudentGradeServiceImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession();
        String studentId = request.getParameter("studentId");
        String courseId = request.getParameter("courseId");

        StudentGrade studentGrade =  new StudentGrade();
        studentGrade.setStudentId(studentId);
        studentGrade.setCourseId(courseId);
        StudentGrade studentGrade1=studentGradeService.getStudentGrade(studentGrade);

        session.setAttribute("studentGrade", studentGrade1);
        response.sendRedirect(request.getContextPath() + "/updateStudentGrade.jsp");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}